<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>turnoff2</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="turnoff.html" title="turnoff" />
    <link rel="next" href="turnon.html" title="turnon" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">turnoff2</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="turnoff.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="turnon.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="turnoff2"></a>
      <div class="titlepage"></div>
      <a id="IndexTurnoff2" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">turnoff2</span>
        </h2>
        <p>turnoff2 — 
      Turn off instance(s) of other instruments at performance time.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp159937008"></a>
        <h2>Description</h2>
        <p>
      Turn off instance(s) of other instruments at performance time.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp160001872"></a>
        <h2>Syntax</h2>
        <pre class="synopsis"><span class="command"><strong>turnoff2</strong></span> kinsno, kmode, krelease
    </pre>
      </div>
      <div class="refsect1">
        <a id="idp160003840"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>kinsno</em></span>
      -- instrument to be turned off (can be fractional) if zero or
      negative, no instrument is turned off
    </p>
        <p>
      <span class="emphasis"><em>kmode</em></span>
      -- sum of the following values:

      </p>
        <div class="itemizedlist">
          <ul class="itemizedlist" style="list-style-type: disc; ">
            <li class="listitem">
              <p>
            		0, 1, or 2: turn off all instances (0), oldest only
            		(1), or newest only (2)
            	</p>
            </li>
            <li class="listitem">
              <p>
            		4: only turn off notes with exactly matching
            		(fractional) instrument number, rather than ignoring
            		fractional part
            	</p>
            </li>
            <li class="listitem">
              <p>
            		8: only turn off notes with indefinite duration (p3
            		&lt; 0 or MIDI)
            	</p>
            </li>
          </ul>
        </div>
        <p>



    </p>
        <p>
      <span class="emphasis"><em>krelease</em></span>
      -- if non-zero, the turned off instances are allowed to release,
      otherwise are deactivated immediately (possibly resulting in
      clicks)
    </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
      As a rule of thumb, you should turn off instruments with a higher instrument number than the one where turnoff is called, as doing otherwise might cause initialization issues.
    </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp160011360"></a>
        <h2>Examples</h2>
        <p>
      The following example uses the turnoff2 opcode, s written by Lou
      Cohen..

      </p>
        <div class="example">
          <a id="idp160012400"></a>
          <p class="title">
            <strong>Example 954. Example of the turnoff2 opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o sin.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span>        <span class="op">=</span>          48000    <span class="comment">;samples per second for sound</span>
<span class="ohdr">kr</span>        <span class="op">=</span>        4800
<span class="ohdr">nchnls</span>    <span class="op">=</span>        1
<span class="ohdr">0dbfs</span>    <span class="op">=</span>        32767

gisine    <span class="ohdr">ftgen</span>    1, 0, 131073, 9, 1, 1, 0                <span class="comment">;single sine tone</span>

<span class="comment">;-----------------------------------------</span>
<span class="oblock">instr</span> 2 <span class="comment">;start</span>
    ktrigger        <span class="opc">init</span>        0
    <span class="octrl">if</span> (ktrigger <span class="op">=</span> 0) then
        kMultiple    <span class="op">=</span>    1.1
        kHz            <span class="op">=</span>    440
        kAmp            <span class="op">=</span>    (<span class="ohdr">0dbfs</span><span class="op">/</span>10)
<span class="comment">;startup four instances of instrument 200</span>
        <span class="opc">event</span>    "i", 200, 0, 3000, kAmp, kHz
        kAmp    <span class="op">=</span>    kAmp <span class="op">*</span> 0.75
        kHz    <span class="op">=</span>    kHz <span class="op">*</span> kMultiple

        <span class="opc">event</span>    "i", 200, 0, 3000, kAmp, kHz
        kAmp    <span class="op">=</span>    kAmp <span class="op">*</span> 0.75
        kHz    <span class="op">=</span>    kHz <span class="op">*</span> kMultiple

        <span class="opc">event</span>    "i", 200, 0, 3000, kAmp, kHz
        kAmp    <span class="op">=</span>    kAmp <span class="op">*</span> 0.75
        kHz    <span class="op">=</span>    kHz <span class="op">*</span> kMultiple

        <span class="opc">event</span>    "i", 200, 0, 3000, kAmp, kHz
        kAmp    <span class="op">=</span>    kAmp <span class="op">*</span> 0.75
        kHz    <span class="op">=</span>    kHz <span class="op">*</span> kMultiple
        ktrigger        <span class="op">=</span>    1
    <span class="octrl">endif</span>
<span class="oblock">endin</span>
<span class="comment">;---------------------------------------------</span>
<span class="oblock">instr</span> 3 <span class="comment">;after 10 seconds, turn off the instruments</span>
    ktrigger <span class="opc">init</span> 1
   <span class="octrl">if</span> (ktrigger<span class="op">==</span>1) then
        <span class="opc">turnoff2</span> 200, 1, 1    <span class="comment">;turn off must recently started instrument instance</span>
        kactive <span class="opc">active</span> 200    <span class="comment">;find out how many are still active</span>
        <span class="opc">printk2</span> kactive       <span class="comment">;print mainly to show progress</span>

        <span class="opc">turnoff2</span>    200, 0, 1    <span class="comment">;turn off all the rest of the instruments</span>
        kactive    <span class="opc">active</span> 200    <span class="comment">;find out how many are still active</span>
        <span class="opc">printk2</span>    kactive, 10    <span class="comment">;print to show progress</span>
<span class="octrl">endif</span>
<span class="oblock">endin</span>
<span class="comment">;----------------------------------------------------</span>
<span class="oblock">instr</span> 200 <span class="comment">;play the tone</span>
kEnv    <span class="opc">linen</span>    1, 0.1, p3, 0.1
ar      <span class="opc">oscil</span>    kEnv<span class="op">*</span>p4, p5, 1
        <span class="opc">out</span>      ar
        <span class="opc">print</span>    p4, p5

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>

<span class="stamnt">i</span>2 0 0.1 
<span class="stamnt">i</span>3 10 0.1
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp160016688"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="turnoff.html" title="turnoff"><em class="citetitle">turnoff</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp160018736"></a>
        <h2>Credits</h2>
        <p>
      </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Istvan Varga</td>
          </tr>
          <tr>
            <td>2005</td>
          </tr>
        </table>
        <p>
    </p>
        <p>New in Csound 5.00</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="turnoff.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="turnon.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">turnoff </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> turnon</td>
        </tr>
      </table>
    </div>
  </body>
</html>
